<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link href="cpip.css" rel="stylesheet" type="text/css" />
    <title>File: /Users/paulross/dev/linux/linux-3.13/arch/x86/include/asm/pvclock.h</title>
  </head>
  <body>
    <h1>File: /Users/paulross/dev/linux/linux-3.13/arch/x86/include/asm/pvclock.h</h1>
    <p>Green shading in the line number column
means the source is part of the translation unit, red means it is conditionally excluded.
Highlighted line numbers link to the translation unit page. Highlighted macros link to
the macro page.</p>
    <pre><a name="1" /><span class="True">       1:</span> <span class="f">#</span><span class="n">ifndef</span> <a href="cpu.c_macros_noref.html#_X0FTTV9YODZfUFZDTE9DS19IXzA_"><span class="b">_ASM_X86_PVCLOCK_H</span></a>
<a name="2" /><span class="True">       2:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_X0FTTV9YODZfUFZDTE9DS19IXzA_"><span class="b">_ASM_X86_PVCLOCK_H</span></a>
<a name="3" /><span class="True">       3:</span> 
<a name="4" /><span class="True">       4:</span> <span class="f">#</span><span class="n">include</span> <span class="f">&lt;</span><span class="b">linux</span><span class="f">/</span><span class="b">clocksource</span><span class="f">.</span><span class="b">h</span><span class="f">&gt;</span>
<a name="5" /><span class="True">       5:</span> <span class="f">#</span><span class="n">include</span> <span class="f">&lt;</span><span class="m">asm</span><span class="f">/</span><span class="b">pvclock</span><span class="f">-</span><span class="b">abi</span><span class="f">.</span><span class="b">h</span><span class="f">&gt;</span>
<a name="6" /><span class="True">       6:</span> 
<a name="7" /><span class="True">       7:</span> <span class="k">/* some helper functions for xen and kvm pv clock sources */</span>
<a name="8" /><span class="True">       8:</span> <span class="b">cycle_t</span> <span class="b">pvclock_clocksource_read</span><span class="f">(</span><span class="m">struct</span> <span class="b">pvclock_vcpu_time_info</span> <span class="f">*</span><span class="b">src</span><span class="f">)</span><span class="f">;</span>
<a name="9" /><span class="True">       9:</span> <span class="b">u8</span> <span class="b">pvclock_read_flags</span><span class="f">(</span><span class="m">struct</span> <span class="b">pvclock_vcpu_time_info</span> <span class="f">*</span><span class="b">src</span><span class="f">)</span><span class="f">;</span>
<a name="10" /><span class="True">      10:</span> <span class="m">void</span> <span class="b">pvclock_set_flags</span><span class="f">(</span><span class="b">u8</span> <span class="b">flags</span><span class="f">)</span><span class="f">;</span>
<a name="11" /><span class="True">      11:</span> <span class="m">unsigned</span> <span class="m">long</span> <span class="b">pvclock_tsc_khz</span><span class="f">(</span><span class="m">struct</span> <span class="b">pvclock_vcpu_time_info</span> <span class="f">*</span><span class="b">src</span><span class="f">)</span><span class="f">;</span>
<a name="12" /><span class="True">      12:</span> <span class="m">void</span> <span class="b">pvclock_read_wallclock</span><span class="f">(</span><span class="m">struct</span> <span class="b">pvclock_wall_clock</span> <span class="f">*</span><span class="b">wall</span><span class="f">,</span>
<a name="13" /><span class="True">      13:</span>                 <span class="m">struct</span> <span class="b">pvclock_vcpu_time_info</span> <span class="f">*</span><span class="b">vcpu</span><span class="f">,</span>
<a name="14" /><span class="True">      14:</span>                 <span class="m">struct</span> <span class="b">timespec</span> <span class="f">*</span><span class="b">ts</span><span class="f">)</span><span class="f">;</span>
<a name="15" /><span class="True">      15:</span> <span class="m">void</span> <span class="b">pvclock_resume</span><span class="f">(</span><span class="m">void</span><span class="f">)</span><span class="f">;</span>
<a name="16" /><span class="True">      16:</span> 
<a name="17" /><span class="True">      17:</span> <span class="m">void</span> <span class="b">pvclock_touch_watchdogs</span><span class="f">(</span><span class="m">void</span><span class="f">)</span><span class="f">;</span>
<a name="18" /><span class="True">      18:</span> 
<a name="19" /><span class="True">      19:</span> <span class="k">/*</span>
<a name="20" /><span class="True">      20:</span> <span class="k"> * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction,</span>
<a name="21" /><span class="True">      21:</span> <span class="k"> * yielding a 64-bit result.</span>
<a name="22" /><span class="True">      22:</span> <span class="k"> */</span>
<a name="23" /><span class="True">      23:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">u64</span> <span class="b">pvclock_scale_delta</span><span class="f">(</span><span class="b">u64</span> <span class="b">delta</span><span class="f">,</span> <a href="cpu.c_macros_ref.html#_dTMyXzA_"><span class="b">u32</span></a> <span class="b">mul_frac</span><span class="f">,</span> <span class="m">int</span> <span class="b">shift</span><span class="f">)</span>
<a name="24" /><span class="True">      24:</span> <span class="f">{</span>
<a name="25" /><span class="True">      25:</span>     <span class="b">u64</span> <span class="b">product</span><span class="f">;</span>
<a name="26" /><span class="False">      26:</span> <span class="f">#</span><span class="n">ifdef</span> <span class="b">__i386__</span>
<a name="27" /><span class="False">      27:</span>     <a href="cpu.c_macros_ref.html#_dTMyXzA_"><span class="b">u32</span></a> <span class="b">tmp1</span><span class="f">,</span> <span class="b">tmp2</span><span class="f">;</span>
<a name="28" /><span class="True">      28:</span> <span class="f">#</span><span class="n">else</span>
<a name="29" /><span class="True">      29:</span>     <span class="b">ulong</span> <span class="b">tmp</span><span class="f">;</span>
<a name="30" /><span class="True">      30:</span> <span class="f">#</span><span class="n">endif</span>
<a name="31" /><span class="True">      31:</span> 
<a name="32" /><span class="True">      32:</span>     <span class="m">if</span> <span class="f">(</span><span class="b">shift</span> <span class="f">&lt;</span> <span class="c">0</span><span class="f">)</span>
<a name="33" /><span class="True">      33:</span>         <span class="b">delta</span> <span class="f">&gt;&gt;=</span> <span class="f">-</span><span class="b">shift</span><span class="f">;</span>
<a name="34" /><span class="True">      34:</span>     <span class="m">else</span>
<a name="35" /><span class="True">      35:</span>         <span class="b">delta</span> <span class="f">&lt;&lt;=</span> <span class="b">shift</span><span class="f">;</span>
<a name="36" /><span class="True">      36:</span> 
<a name="37" /><span class="False">      37:</span> <span class="f">#</span><span class="n">ifdef</span> <span class="b">__i386__</span>
<a name="38" /><span class="False">      38:</span>     <span class="b">__asm__</span> <span class="f">(</span>
<a name="39" /><span class="False">      39:</span>         <span class="e">&quot;mul  %5       ; &quot;</span>
<a name="40" /><span class="False">      40:</span>         <span class="e">&quot;mov  %4,%%eax ; &quot;</span>
<a name="41" /><span class="False">      41:</span>         <span class="e">&quot;mov  %%edx,%4 ; &quot;</span>
<a name="42" /><span class="False">      42:</span>         <span class="e">&quot;mul  %5       ; &quot;</span>
<a name="43" /><span class="False">      43:</span>         <span class="e">&quot;xor  %5,%5    ; &quot;</span>
<a name="44" /><span class="False">      44:</span>         <span class="e">&quot;add  %4,%%eax ; &quot;</span>
<a name="45" /><span class="False">      45:</span>         <span class="e">&quot;adc  %5,%%edx ; &quot;</span>
<a name="46" /><span class="False">      46:</span>         <span class="f">:</span> <span class="e">&quot;=A&quot;</span> <span class="f">(</span><span class="b">product</span><span class="f">)</span><span class="f">,</span> <span class="e">&quot;=r&quot;</span> <span class="f">(</span><span class="b">tmp1</span><span class="f">)</span><span class="f">,</span> <span class="e">&quot;=r&quot;</span> <span class="f">(</span><span class="b">tmp2</span><span class="f">)</span>
<a name="47" /><span class="False">      47:</span>         <span class="f">:</span> <span class="e">&quot;a&quot;</span> <span class="f">(</span><span class="f">(</span><a href="cpu.c_macros_ref.html#_dTMyXzA_"><span class="b">u32</span></a><span class="f">)</span><span class="b">delta</span><span class="f">)</span><span class="f">,</span> <span class="e">&quot;1&quot;</span> <span class="f">(</span><span class="f">(</span><a href="cpu.c_macros_ref.html#_dTMyXzA_"><span class="b">u32</span></a><span class="f">)</span><span class="f">(</span><span class="b">delta</span> <span class="f">&gt;&gt;</span> <span class="c">32</span><span class="f">)</span><span class="f">)</span><span class="f">,</span> <span class="e">&quot;2&quot;</span> <span class="f">(</span><span class="b">mul_frac</span><span class="f">)</span> <span class="f">)</span><span class="f">;</span>
<a name="48" /><span class="True">      48:</span> <span class="f">#</span><span class="n">elif</span> <span class="b">defined</span><span class="f">(</span><a href="cpu.c_macros_ref.html#_X194ODZfNjRfX18w"><span class="b">__x86_64__</span></a><span class="f">)</span>
<a name="49" /><span class="True">      49:</span>     <span class="b">__asm__</span> <span class="f">(</span>
<a name="50" /><span class="True">      50:</span>         <span class="e">&quot;mulq %[mul_frac] ; shrd $32, %[hi], %[lo]&quot;</span>
<a name="51" /><span class="True">      51:</span>         <span class="f">:</span> <span class="f">[</span><span class="b">lo</span><span class="f">]</span><span class="e">&quot;=a&quot;</span><span class="f">(</span><span class="b">product</span><span class="f">)</span><span class="f">,</span>
<a name="52" /><span class="True">      52:</span>           <span class="f">[</span><span class="b">hi</span><span class="f">]</span><span class="e">&quot;=d&quot;</span><span class="f">(</span><span class="b">tmp</span><span class="f">)</span>
<a name="53" /><span class="True">      53:</span>         <span class="f">:</span> <span class="e">&quot;0&quot;</span><span class="f">(</span><span class="b">delta</span><span class="f">)</span><span class="f">,</span>
<a name="54" /><span class="True">      54:</span>           <span class="f">[</span><span class="b">mul_frac</span><span class="f">]</span><span class="e">&quot;rm&quot;</span><span class="f">(</span><span class="f">(</span><span class="b">u64</span><span class="f">)</span><span class="b">mul_frac</span><span class="f">)</span><span class="f">)</span><span class="f">;</span>
<a name="55" /><span class="False">      55:</span> <span class="f">#</span><span class="n">else</span>
<a name="56" /><span class="False">      56:</span> <span class="f">#</span><span class="n">error</span> <span class="b">implement</span> <span class="b">me</span><span class="f">!</span>
<a name="57" /><span class="True">      57:</span> <span class="f">#</span><span class="n">endif</span>
<a name="58" /><span class="True">      58:</span> 
<a name="59" /><span class="True">      59:</span>     <span class="m">return</span> <span class="b">product</span><span class="f">;</span>
<a name="60" /><span class="True">      60:</span> <span class="f">}</span>
<a name="61" /><span class="True">      61:</span> 
<a name="62" /><span class="True">      62:</span> <span class="m">static</span> <a href="cpu.c_macros_ref.html#_X19hbHdheXNfaW5saW5lXzA_"><span class="b">__always_inline</span></a>
<a name="63" /><span class="True">      63:</span> <span class="b">u64</span> <span class="b">pvclock_get_nsec_offset</span><span class="f">(</span><span class="m">const</span> <span class="m">struct</span> <span class="b">pvclock_vcpu_time_info</span> <span class="f">*</span><span class="b">src</span><span class="f">)</span>
<a name="64" /><span class="True">      64:</span> <span class="f">{</span>
<a name="65" /><span class="True">      65:</span>     <span class="b">u64</span> <span class="b">delta</span> <span class="f">=</span> <span class="b">__native_read_tsc</span><span class="f">(</span><span class="f">)</span> <span class="f">-</span> <span class="b">src</span><span class="f">-&gt;</span><span class="b">tsc_timestamp</span><span class="f">;</span>
<a name="66" /><span class="True">      66:</span>     <span class="m">return</span> <span class="b">pvclock_scale_delta</span><span class="f">(</span><span class="b">delta</span><span class="f">,</span> <span class="b">src</span><span class="f">-&gt;</span><span class="b">tsc_to_system_mul</span><span class="f">,</span>
<a name="67" /><span class="True">      67:</span>                    <span class="b">src</span><span class="f">-&gt;</span><span class="b">tsc_shift</span><span class="f">)</span><span class="f">;</span>
<a name="68" /><span class="True">      68:</span> <span class="f">}</span>
<a name="69" /><span class="True">      69:</span> 
<a name="70" /><span class="True">      70:</span> <span class="m">static</span> <a href="cpu.c_macros_ref.html#_X19hbHdheXNfaW5saW5lXzA_"><span class="b">__always_inline</span></a>
<a name="71" /><span class="True">      71:</span> <span class="m">unsigned</span> <span class="b">__pvclock_read_cycles</span><span class="f">(</span><span class="m">const</span> <span class="m">struct</span> <span class="b">pvclock_vcpu_time_info</span> <span class="f">*</span><span class="b">src</span><span class="f">,</span>
<a name="72" /><span class="True">      72:</span>                    <span class="b">cycle_t</span> <span class="f">*</span><span class="b">cycles</span><span class="f">,</span> <span class="b">u8</span> <span class="f">*</span><span class="b">flags</span><span class="f">)</span>
<a name="73" /><span class="True">      73:</span> <span class="f">{</span>
<a name="74" /><span class="True">      74:</span>     <span class="m">unsigned</span> <span class="b">version</span><span class="f">;</span>
<a name="75" /><span class="True">      75:</span>     <span class="b">cycle_t</span> <span class="b">ret</span><span class="f">,</span> <span class="b">offset</span><span class="f">;</span>
<a name="76" /><span class="True">      76:</span>     <span class="b">u8</span> <span class="b">ret_flags</span><span class="f">;</span>
<a name="77" /><span class="True">      77:</span> 
<a name="78" /><span class="True">      78:</span>     <span class="b">version</span> <span class="f">=</span> <span class="b">src</span><span class="f">-&gt;</span><span class="b">version</span><span class="f">;</span>
<a name="79" /><span class="True">      79:</span>     <span class="k">/* Note: emulated platforms which do not advertise SSE2 support</span>
<a name="80" /><span class="True">      80:</span> <span class="k">     * result in kvmclock not using the necessary RDTSC barriers.</span>
<a name="81" /><span class="True">      81:</span> <span class="k">     * Without barriers, it is possible that RDTSC instruction reads from</span>
<a name="82" /><span class="True">      82:</span> <span class="k">     * the time stamp counter outside rdtsc_barrier protected section</span>
<a name="83" /><span class="True">      83:</span> <span class="k">     * below, resulting in violation of monotonicity.</span>
<a name="84" /><span class="True">      84:</span> <span class="k">     */</span>
<a name="85" /><span class="True">      85:</span>     <span class="b">rdtsc_barrier</span><span class="f">(</span><span class="f">)</span><span class="f">;</span>
<a name="86" /><span class="True">      86:</span>     <span class="b">offset</span> <span class="f">=</span> <span class="b">pvclock_get_nsec_offset</span><span class="f">(</span><span class="b">src</span><span class="f">)</span><span class="f">;</span>
<a name="87" /><span class="True">      87:</span>     <span class="b">ret</span> <span class="f">=</span> <span class="b">src</span><span class="f">-&gt;</span><span class="b">system_time</span> <span class="f">+</span> <span class="b">offset</span><span class="f">;</span>
<a name="88" /><span class="True">      88:</span>     <span class="b">ret_flags</span> <span class="f">=</span> <span class="b">src</span><span class="f">-&gt;</span><span class="b">flags</span><span class="f">;</span>
<a name="89" /><span class="True">      89:</span>     <span class="b">rdtsc_barrier</span><span class="f">(</span><span class="f">)</span><span class="f">;</span>
<a name="90" /><span class="True">      90:</span> 
<a name="91" /><span class="True">      91:</span>     <span class="f">*</span><span class="b">cycles</span> <span class="f">=</span> <span class="b">ret</span><span class="f">;</span>
<a name="92" /><span class="True">      92:</span>     <span class="f">*</span><span class="b">flags</span> <span class="f">=</span> <span class="b">ret_flags</span><span class="f">;</span>
<a name="93" /><span class="True">      93:</span>     <span class="m">return</span> <span class="b">version</span><span class="f">;</span>
<a name="94" /><span class="True">      94:</span> <span class="f">}</span>
<a name="95" /><span class="True">      95:</span> 
<a name="96" /><span class="True">      96:</span> <span class="m">struct</span> <span class="b">pvclock_vsyscall_time_info</span> <span class="f">{</span>
<a name="97" /><span class="True">      97:</span>     <span class="m">struct</span> <span class="b">pvclock_vcpu_time_info</span> <span class="b">pvti</span><span class="f">;</span>
<a name="98" /><span class="True">      98:</span> <span class="f">}</span> <span class="b">__attribute__</span><span class="f">(</span><span class="f">(</span><span class="b">__aligned__</span><span class="f">(</span><a href="cpu.c_macros_ref.html#_U01QX0NBQ0hFX0JZVEVTXzA_"><span class="b">SMP_CACHE_BYTES</span></a><span class="f">)</span><span class="f">)</span><span class="f">)</span><span class="f">;</span>
<a name="99" /><span class="True">      99:</span> 
<a name="100" /><span class="True">     100:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_UFZUSV9TSVpFXzA_"><span class="b">PVTI_SIZE</span></a> <span class="m">sizeof</span><span class="f">(</span><span class="m">struct</span> <span class="b">pvclock_vsyscall_time_info</span><span class="f">)</span>
<a name="101" /><span class="True">     101:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_UFZDTE9DS19WU1lTQ0FMTF9OUl9QQUdFU18w"><span class="b">PVCLOCK_VSYSCALL_NR_PAGES</span></a> <span class="f">(</span><span class="f">(</span><span class="f">(</span><a href="cpu.c_macros_ref.html#_TlJfQ1BVU18w"><span class="b">NR_CPUS</span></a><span class="f">-</span><span class="c">1</span><span class="f">)</span><span class="f">/</span><span class="f">(</span><a href="cpu.c_macros_ref.html#_UEFHRV9TSVpFXzA_"><span class="b">PAGE_SIZE</span></a><span class="f">/</span><a href="cpu.c_macros_noref.html#_UFZUSV9TSVpFXzA_"><span class="b">PVTI_SIZE</span></a><span class="f">)</span><span class="f">)</span><span class="f">+</span><span class="c">1</span><span class="f">)</span>
<a name="102" /><span class="True">     102:</span> 
<a name="103" /><span class="True">     103:</span> <span class="m">int</span> <a href="cpu.c_macros_ref.html#_X19pbml0XzA_"><span class="b">__init</span></a> <span class="b">pvclock_init_vsyscall</span><span class="f">(</span><span class="m">struct</span> <span class="b">pvclock_vsyscall_time_info</span> <span class="f">*</span><span class="b">i</span><span class="f">,</span>
<a name="104" /><span class="True">     104:</span>                  <span class="m">int</span> <span class="b">size</span><span class="f">)</span><span class="f">;</span>
<a name="105" /><span class="True">     105:</span> <span class="m">struct</span> <span class="b">pvclock_vcpu_time_info</span> <span class="f">*</span><span class="b">pvclock_get_vsyscall_time_info</span><span class="f">(</span><span class="m">int</span> <span class="b">cpu</span><span class="f">)</span><span class="f">;</span>
<a name="106" /><span class="True">     106:</span> 
<a name="107" /><span class="True">     107:</span> <span class="f">#</span><span class="n">endif</span> <span class="k">/* _ASM_X86_PVCLOCK_H */</span>
<a name="108" /><span class="True">     108:</span> </pre>
  </body>
</html>
